package com.app.acitivty;

import java.util.ArrayList;

import com.app.activity.R;
import com.app.components.TopMenu;
import com.app.data.InnItem;
import com.app.data.LineItem;
import com.app.data.ScenicItem;
import com.app.data.YouhuiItem;
import com.app.service.HttpCallBack;
import com.app.service.YouhuiService;
import com.app.service.adapter.YouhuiAdapter;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class YouHuiActivity extends Activity implements HttpCallBack,OnItemClickListener{
	
	ProgressDialog progressDialog;
	ArrayList<YouhuiItem> datalist;
	
	public static YouhuiItem cItem;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.youhui);
		requestYouhuiList();
		TopMenu topMenu = new TopMenu(this, "返回", new OnClickListener() {

			@Override
			public void onClick(View v) {
				YouHuiActivity.this.finish();
				
				
			}
		}, R.drawable.top_button_unselect, R.drawable.top_button_selected, "优惠券");
		topMenu.onCreate();
		progressDialog = new ProgressDialog(this);
		progressDialog.setTitle("提示");
		progressDialog.setMessage("读取数据中...");
		progressDialog.setCancelable(false);
		progressDialog.setIndeterminate(true);
		progressDialog.show();
	}
	
	private void requestYouhuiList() {
		YouhuiService service = new YouhuiService(this);
		service.execute("");
	}

	@Override
	public void hotelFinishLoad(int code, ArrayList<InnItem> list) {
		
	}

	@Override
	public void lineFinishLoad(int code, ArrayList<LineItem> list) {
	}

	@Override
	public void ticketFinishLoad(int code, ArrayList<ScenicItem> list) {
		
	}

	@Override
	public void youhuiFinishLoad(int code, ArrayList<YouhuiItem> list)
	{
		System.out.println("youhuiFinishLoad" + list);
		datalist = list;
		ListView listView = (ListView)findViewById(R.id.lvYouhuiList);
		System.out.println("activity" + listView);
		YouhuiAdapter adapter = new YouhuiAdapter(this,list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
		progressDialog.dismiss();
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int postion, long id) {
		YouhuiItem item = datalist.get(postion);
		Intent intent = new Intent(this,YouhuiDetailActivity.class);
		//intent.putExtra("item", item);
		cItem =item;
		startActivity(intent);
	}
}
